<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    #include("common/header.html")
</head>

<body>
<div style="margin: 15px;">
    <div class="layui-form" id="validate">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="text" id="password" is-yz="true" yz-type="null" lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="text" id="pass_new" is-yz="true" yz-type="null,password" eq-id='pass_required' lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">再次输入新密码</label>
            <div class="layui-input-block">
                <input type="text" id="pass_required" is-yz="true" yz-type="null,password" eq-id='pass_new' lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" onclick="ok()">立即提交</button>
                <button class="layui-btn layui-btn-primary" onclick="reset()">重置</button>
            </div>
        </div>
    </div>
</div>
<script>

    var layer;
    layui.use(['layer'], function () {
        layer = layui.layer;
    });

    var validator = $("#validate").validator();

    function ok() {

        if(!validator.check()){
            return;
        }

        var password = $("#password").val();
        var newPass = $("#pass_required").val();

        $.ajax({
            url: "/teacher/password",
            type: "put",
            dataType: "json",
            data: {"password": password, "newPass": newPass},
            success: function (r) {
                console.log(r);

                if (r.code == -1) {
                    layer.msg(r.msg);
                    return;
                }

                layer.msg('修改成功!', {time: 1000}, function () {
                    location.reload();
                });
            }
        });
        
    }

    function reset() {
        $("#password").val("");
        $("#pass_new").val("");
        $("#pass_required").val("");
    }

</script>
</body>

</html>